package de.siro.notie_surface;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class SplashActivity extends Activity {

	private static long SLEEP_TIME = 3;
	private static String TAG = SplashActivity.class.getName();

	public void onAttachedToWindow() {
		super.onAttachedToWindow();
		Window window = getWindow();
		window.setFormat(PixelFormat.RGBA_8888);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.splash);

		IntentLauncher iLauncher = new IntentLauncher();
		iLauncher.start();
		startAnimations();

	}

	private class IntentLauncher extends Thread {

		@Override
		public void run() {
			try {
				Thread.sleep(SLEEP_TIME * 1000);
			} catch (Exception e) {
				Log.e(TAG, e.getMessage());
			}
			Intent intent = new Intent(SplashActivity.this, MainActivity.class);
			SplashActivity.this.startActivity(intent);
			SplashActivity.this.finish();
		}

	}

	private void startAnimations() {

		Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
		anim.reset();
		LinearLayout l = (LinearLayout) findViewById(R.id.vsbg);
		l.clearAnimation();
		l.startAnimation(anim);

		ImageView iv = (ImageView) findViewById(R.id.vsnobg);
		anim = AnimationUtils.loadAnimation(this, R.anim.translate);
		anim.reset();
		iv.clearAnimation();
		iv.startAnimation(anim);
//schinken
	}

}
